home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1999 March
/
EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso
/
earcd
/
devel
/
vbcc-68k-src
/
machines
/
amiga68k
/
libsrc
/
stdio
/
fopen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-01
|
1KB
|
36 lines
#include <stddef.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <proto/dos.h>
extern FILE *_firstfile,*_lastfile;
FILE *fopen(const char *name,const char *mode)
{
FILE *f;long amigamode=0;int append;
if(*mode=='w') amigamode=MODE_NEWFILE; else amigamode=MODE_OLDFILE;
if(*mode=='a') append=1; else append=0;
if(!(f=malloc(sizeof(FILE)))) return(0);
f->count=0;
f->base=0;
f->bufsize=0;
f->next=0;
if(*mode=='r') f->flags=_READABLE; else f->flags=_WRITEABLE;
if(*++mode=='b') mode++;
if(*mode=='+') {f->flags|=_READABLE|_WRITEABLE;amigamode=MODE_READWRITE;}
f->filehandle=(char *)Open((STRPTR)name,amigamode);
if(!f->filehandle){free(f);return(0);}
if(IsInteractive((BPTR)f->filehandle)) f->flags|=_LINEBUF;
if(_lastfile){
_lastfile->next=f;f->prev=_lastfile;_lastfile=f;
}else{
_firstfile=_lastfile=f;
}
if(append) fseek(f,0,SEEK_END);
return(f);
}